﻿//var MONTH_COMBO = "CR.CB.MONTH";
//var YEAR_COMBO = "CR.CB.YEAR";
var START_DATE = "CR.DT.START";
var END_DATE = "CR.DT.END";
var FILTER_BUTTON = "CR.BTN.FILTER";

FilterReport = function(step){
    
//    var cbMonth = $id(MONTH_COMBO);
//    var cbYear = $id(YEAR_COMBO);
    
    var dtmStart = $id(START_DATE);
    var dtmEnd = $id(END_DATE);
    
    var comparation = compareDates(dtmStart.value,"dd-MMM-yyyy",dtmEnd.value,"dd-MMM-yyyy")
    
    if( comparation > 0 )
    {
        alert("End Date is earlier than Start Date");
        return;
    }
//    var iMonth = 0;
//    var iYear = 0;
    
//    selectobj.selectedIndex
//    
//    .options[0].value
    
//    if( step != undefined )
//    {
//        var iMonthSelected = cbMonth.selectedIndex;
//        var iYearSelected = cbYear.selectedIndex;
//        
//        if( iMonthSelected + step < cbMonth.options.length && iMonthSelected + step >= 0 )
//        {
//            var currentMonth = new Date().getMonth();
//            
//            if( iYearSelected == 0 )
//            {
//                if( iMonthSelected + step <= currentMonth )
//                {
//                    iMonthSelected = iMonthSelected + step;
//                }
//                else
//                {
//                    return false;
//                }
//            }
//            else
//            {
//                iMonthSelected = iMonthSelected + step;
//            }
//        }
//        else if( iYearSelected - step < cbYear.options.length && iYearSelected - step >= 0 )
//        {
//            iYearSelected = iYearSelected - step;        
//            
//            iMonthSelected = step > 0 ? 0 : cbMonth.options.length - 1;
//        }
//        
//        cbMonth.selectedIndex = iMonthSelected;
//        cbYear.selectedIndex = iYearSelected;
//    }
//    
//    iMonth = cbMonth.options[cbMonth.selectedIndex].value;
//    iYear = cbYear.options[cbYear.selectedIndex].value;
    
    dgMain_c.PerformCallback(dtmStart.value + DELIMITER + dtmEnd.value);
    chrMain_c.PerformCallback(dtmStart.value + DELIMITER + dtmEnd.value);
        
}

toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var lnk = $id("lnk_" + fsid);
    
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    
    if( lnk != null )
    {
        lnk.style.display = display;
    }
}

StartLoadingAnimation = function(div){
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    
}

EndLoadingAnimation = function(div){
    div.innerHTML = "";    
}

FilterSeries = function()
{
    var dtmStart = $id(START_DATE);
    var dtmEnd = $id(END_DATE);
    
    var comparation = compareDates(dtmStart.value,"dd-MMM-yyyy",dtmEnd.value,"dd-MMM-yyyy")
    
    if( comparation > 0 )
    {
        alert("End Date is earlier than Start Date");
        return;
    }
    
    var inputs = $nm("chk");
    var output = "";
    
    for(var i=0; i < inputs.length; i++ )
    {
        var item = inputs[i];
        if( i > 0 && item.checked)
        {
            output += NEWLINE;
        }
        
        if(item.checked)
        {
            output += item.id;
        }
    }
    
    dgMain_c.PerformCallback(dtmStart.value + DELIMITER + dtmEnd.value + DELIMITER + output);
    chrMain_c.PerformCallback(dtmStart.value + DELIMITER + dtmEnd.value + DELIMITER + output);
    
}